export default {
    data: function () {
        return {
            showBg: false,                  //是否显示背景图片，默认是不显示的
            scrollTopValue: 0,              //针对页面滚动事件，固定背景问题的页面滚动值
        }
    },
    computed: {
        //适用平台判断，微信端和chrome端变现不一致
        isWX() {
            var ua = navigator.userAgent.toLowerCase();
            if (ua.match(/MicroMessenger/i) == "micromessenger") {
                return true;
            } else {
                return false;
            }
        },
        //返回vuex中的图片域名地址
        imgUrl() {
            return this.$store._modules.root._children.a.state;
        },
    },
    methods: {
        toNext(url, params) {
            if (!url && url != '') {
                return;
            }
            this.$router.push({
                path: "/" + url,
                query: { ...params }
            });
        },
        //弹出关闭popup窗口时的执行回调
        bodyFixed(state) {
            if (state) {
                this.scrollTopValue = document.body.scrollTop;
                document.body.style.top = - this.scrollTopValue + 'px';
                document.body.style.position = 'fixed';
            } else {
                document.body.style.position = '';
                document.body.scrollTop = this.scrollTopValue;
            }
        }
    }
}
//判断是否注册过的方法，没有就直接跳到绑定手机号页面
const isRegPhoneNumber = {
    methods: {
        isRegPhone() {
            let is = this.$store.state.b.isRegisterPhone;
            if (!is) {
                this.$router.push({ path: '/bindPhone' });
            }
            return is;
        }
    }
}

const restShare = {
    methods: {
        // 微信分享重置
        resetShareLink() {
            var link = location.origin;
            wx.onMenuShareAppMessage({
                title: "你的好友分享了一个公众号！",
                desc: "你的好友分享了一个公众号，速速关注吧",
                link: link,
                imgUrl: "../../images/gift.png",
                type: 'link', // 分享类型,music、video或link，不填默认为link
                success: function () {
                    // alert("分享成功！")
                    this.shareState = true;
                },
                cancel: function () {

                }
            })
        },
        
    }
}
import { setWXConfig } from 'src/methods/baseinfo.js';
const WXSHARE = {
    created(){
        setWXConfig(window.location.href.split('#')[0]);
        wx.showOptionMenu();
    },
    methods:{
        shareWx(link,title,desc,imgUrl,successCB,errorCB){
            wx.showOptionMenu();
            wx.onMenuShareAppMessage({
                title: title,
                desc:desc,
                link:link,
                imgUrl:imgUrl,
                type: 'link',
                success: function () {
                    successCB && successCB();
                },
                cancel: function () {
                    errorCB && errorCB();
                }
            });
        }
    },
    beforeRouterLeave(to,from,next){
        wx.hideOptionMenu();
        next();
    }
}

export {
    isRegPhoneNumber,
    restShare,
    WXSHARE,
}